import java.util.Stack;

public class MinStack {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MinStack() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int val) {
        if(stack2.empty()) {
            stack2.push(val);
            stack1.push(val);
        }else {
            if(val <= stack2.peek()) {
                stack2.push(val);
            }
            stack1.push(val);
        }
    }

    public void pop() {
        if(stack1.empty()) {
            return;
        }
        int pop1 = stack1.pop();
        if(pop1 == stack2.peek()) {
            stack2.pop();
        }
    }

    public int top() {
        if(stack1.empty()) {
            return -1;
        }
        return stack1.peek();
    }

    public int getMin() {
        if(!stack2.empty()) {
            return stack2.peek();
        }
        return -1;
    }


}